<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>AFC设备维修系统-角色详情</title>
		<style>
		#purviewTree {
			margin-top: 10px;
			border: 1px solid #617775;
			background: #f0f6e4;
			min-width: 180px;
			max-height: 400px;
			overflow-y: scroll;
			overflow-x: auto;
		}
		</style>
	</head>

	<body>
		<jsp:include page="/jsp/common/top.jsp"></jsp:include>
		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<!-- 导航菜单 -->
				<jsp:include page="/jsp/common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
				
				<table class="condition" style="width:100%; font-size:14px; font-weight:bold; color:#000000;" align="center">
					<tr>
						<td>
						<s:if test="%{null != role}">
							<input type="button" class="btn-title" value="新增" onclick="javascript:window.location.href='toRoleAdd.action';" />
							&nbsp;&nbsp;&nbsp;
							<input type="button" class="btn-title" value="编辑" onclick="javascript:window.location.href='toRoleEdit.action?role.id=${role.id }';" />
							&nbsp;&nbsp;&nbsp;
							<input type="button" class="btn-title" value="删除" onclick="del('${role.rolecode}');" />
							&nbsp;&nbsp;&nbsp;</s:if>
							<input type="button" class="btn-title" value="返回" onclick="javascript:window.location.href='getRoleList.action';" />
						</td>
					</tr>
				</table>
				
					<div id="add_div">
						<table class="table_add" style="width: 100%;">
						<s:if test="%{null == role}">
							<tr>
								<th style="width: 150px; text-align: center;" colspan="3">
									<font color="red"> 该条记录不存在或已删除！</font>								
								</th>
							</tr>
							</s:if>
							<s:else>
							<tr>
								<th style="width:20%;">
									角色编号：
								</th>
								<td style="width:25%;">
									${role.rolecode }
								</td>
								<th style="width:25%;">
									角色名称：
								</th>
								<td>
									${role.rolename }
								</td>
							</tr>
							<tr>
								<th style="width:20%;">
									权限：
								</th>
								<td style="width:25%;">
									<a href="#" id="showPurview" onclick="showMenu('showPurview', 'roleContent');" style="color: #0078B6;text-decoration: underline" ><b>查看权限<b></b>  </a>
								</td>
								<th style="width:25%;">
									角色操作范围：
								</th>
								<td style="width:25%;">
									${role.roleRange}
								</td>
							</tr>
 					
							<tr>
								<th style="width:20%;">
									角色描述：
								</th>
								<td colspan="3"  style="word-break:break-all">
									${role.mark } 
								</td>
							</tr>
 					</s:else>
						</table>
					</div>
					<div style="margin: 8px 0 0 150px;">
					</div>
				</div>
			</div>
		</div>

		<div id="roleContent" class="menuContent"
			style="display: none; position: absolute;">
			<ul id="purviewTree" class="ztree" style="margin-top: 0;"></ul>
		</div>
		<!-- 顶部end -->
		<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
<script type="text/javascript">
	
	//获取后台数据显示组织架构
	var purview =${flag};
	var setting = {
		check: {
			enable: true
		},
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeClick: beforeClick,
			onCheck: onCheck
		}
	};
		
	function beforeClick(treeId, treeNode) {
		var zTree = jQuery.fn.zTree.getZTreeObj("purviewTree");
		zTree.checkNode(treeNode, !treeNode.checked, true, true);
		return false;
	}
	//选中事件
	function onCheck(e, treeId, treeNode) {
	
		var zTree = jQuery.fn.zTree.getZTreeObj("purviewTree"),
		nodes = zTree.getCheckedNodes(true),
		v = "";
		var vid ="";
		for (var i=0, l=nodes.length; i<l; i++) {
			v += nodes[i].name + ",";
			vid+=nodes[i].id + ",";
		}
		if (v.length > 0 ) v = v.substring(0, v.length-1);
		if (vid.length > 0 ) vid = vid.substring(0, vid.length-1);
	}
	
	//隐藏架构
	function hideMenu(divId) {
		$("#" + divId).fadeOut("fast");
		$("body").unbind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}

	//组织架构弹出窗
	function showMenu(objId, divId) {
		var cityObj = $("#" + objId);
		var cityOffset = $("#" + objId).position();
		$("#" + divId).css( {
			left : cityOffset.left + "px",
			top : cityOffset.top + cityObj.outerHeight() + "px"
		}).slideDown("fast");
		$("body").bind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}

	//页面加载
	$(function() {
	
		//添加高亮显示
		//selectNav('nav2');
		
		//设置架构弹出框
		$.fn.zTree.init($("#purviewTree"), setting, purview);
	});

	//鼠标点击别的地方隐藏弹出属性菜单
	function onBodyDown(event) {
		var divId = event.data.tempDiv;
		if (!(event.target.id == "showPurview" || $(event.target).parents(
				"#" + divId).length > 0)) {
			hideMenu(divId);
		}
	}
	//删除
	function del(accountid){
		if(confirm('确定删除该条记录?')){
			$.ajax({
		        url: 'delete.action?role.rolecode='+ accountid,
		        type:"POST",
		        cache:false,
		        success: function(message){
			    	if(message == "success"){
		        		alert("删除成功！");
		        		window.location.href="getRoleList.action";
		        	}else if(message="exist"){
		        		alert("当前角色正在使用,暂不能删除！");
		        	}else if(message=="error"){
							window.location.href="goError.action";
					}else{
			    		alert('删除失败！');
		        	}
		   		}
	     	});
		}
	}
</script>
	</body>
</html>
